package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.LawsRegulationsTypeAddDTO;
import org.jsola.hr.dto.LawsRegulationsTypeUpdateDTO;
import org.jsola.hr.entity.LawsRegulationsTypeDO;
import org.jsola.hr.query.LawsRegulationsTypeQuery;
import org.jsola.hr.service.ILawsRegulationsTypeService;
import org.jsola.hr.vo.LawsRegulationsTypeVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 卫人云-政策法规分组
 *
 * @author zhr
 */
@Component
public class LawsRegulationsTypeTestHelper extends BaseTestHelper {
    
    @Autowired
    private ILawsRegulationsTypeService lawsRegulationsTypeService;

    /**
     * 生成add测试数据
     * @return LawsRegulationsTypeAddDTO
     */
    public LawsRegulationsTypeAddDTO getLawsRegulationsTypeAddDTO(){
        LawsRegulationsTypeAddDTO lawsRegulationsTypeAddDTO = new LawsRegulationsTypeAddDTO();
        lawsRegulationsTypeAddDTO.setCode(getRandomValue("varchar",50));
        lawsRegulationsTypeAddDTO.setName(getRandomValue("varchar",50));
        lawsRegulationsTypeAddDTO.setSort(SafeKit.getInteger(getRandomValue("int",10)));
        return lawsRegulationsTypeAddDTO;
    }


    /**
     * 生成update测试数据
     * @return LawsRegulationsTypeUpdateDTO
     */
    public LawsRegulationsTypeUpdateDTO getLawsRegulationsTypeUpdateDTO(LawsRegulationsTypeVO lawsRegulationsTypeVO){
        return lawsRegulationsTypeService.selectDOById(lawsRegulationsTypeVO.getId(), SITE_ID).to(LawsRegulationsTypeUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return LawsRegulationsTypeQuery
     */
    public LawsRegulationsTypeQuery getLawsRegulationsTypeQuery() {
        LawsRegulationsTypeQuery lawsRegulationsTypeQuery = new LawsRegulationsTypeQuery();
        List<LawsRegulationsTypeDO> lawsRegulationsTypeDOList = lawsRegulationsTypeService.list(new LawsRegulationsTypeDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(lawsRegulationsTypeDOList)) {
            LawsRegulationsTypeDO lawsRegulationsTypeDO = lawsRegulationsTypeDOList.get(0);
            lawsRegulationsTypeQuery = lawsRegulationsTypeDO.to(LawsRegulationsTypeQuery.class);
        }
        return lawsRegulationsTypeQuery;
    }

    /**
     * 保存示例
     * @return LawsRegulationsTypeVO
     */
    public LawsRegulationsTypeVO saveLawsRegulationsTypeExample(){
        LawsRegulationsTypeAddDTO addDTO = this.getLawsRegulationsTypeAddDTO();
        LawsRegulationsTypeVO lawsRegulationsTypeVO = lawsRegulationsTypeService.save(addDTO,buildTokenUser());
        return lawsRegulationsTypeVO;
    }


}

